<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <springProperty scope="context" name="loggingRoot" source="logging.path"/>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
                <pattern>
                    %d{yyyy-MM-dd HH:mm:ss.SSS}, %p, %c, %F, %t, %L, %M, %tid, trace-id:%X{traceId} %m%n
                </pattern>
            </layout>
        </encoder>
    </appender>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <!-- 对日志进行格式化 -->
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
                <pattern>
                    %d{yyyy-MM-dd HH:mm:ss.SSS}, %p, %c, %F, %t, %L, %M, %tid, trace-id:%X{traceId} %m%n
                </pattern>
            </layout>
        </encoder>
    </appender>

    <appender name="InfoFile"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <file>${r'${loggingRoot}'}/info.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${r'${loggingRoot}'}/info_%d{yyyy-MM-dd.HH}.log</FileNamePattern>
            <maxHistory>7</maxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
                <pattern>
                    %d{yyyy-MM-dd HH:mm:ss.SSS}, %p, %c, %F, %t, %L, %M, %tid, trace-id:%X{traceId} %m%n
                </pattern>
            </layout>
        </encoder>
    </appender>

    <appender name="WarnFile"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARN</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <file>${r'${loggingRoot}'}/warn.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${r'${loggingRoot}'}/warn_%d{yyyy-MM-dd.HH}.log</FileNamePattern>
            <maxHistory>7</maxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
                <pattern>
                    %d{yyyy-MM-dd HH:mm:ss.SSS}, %p, %c, %F, %t, %L, %M, %tid, trace-id:%X{traceId} %m%n
                </pattern>
            </layout>
        </encoder>
    </appender>

    <appender name="ErrorFile"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <file>${r'${loggingRoot}'}/error.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${r'${loggingRoot}'}/error_%d{yyyy-MM-dd.HH}.log</FileNamePattern>
            <maxHistory>7</maxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
                <pattern>
                    %d{yyyy-MM-dd HH:mm:ss.SSS}, %p, %c, %F, %t, %L, %M, %tid, trace-id:%X{traceId} %m%n
                </pattern>
            </layout>
        </encoder>
    </appender>

    <root>
        <level value="INFO"/>
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="InfoFile"/>
        <appender-ref ref="WarnFile"/>
        <appender-ref ref="ErrorFile"/>
    </root>
</configuration>
